package com.wedu.view;

import com.wedu.entity.Student;
import com.wedu.service.StudentService;
import com.wedu.service.impl.StudentServiceImpl;
import com.wedu.util.TSUtils;
import org.junit.Test;

import java.awt.dnd.DragGestureEvent;
import java.sql.SQLException;
import java.util.Scanner;

/**
 * @author 乱码酱
 * @date ：2022-09-28 22:54
 * @program: javaUBD
 * @create:
 */
public class Update1 {
    private StudentService studentService = new StudentServiceImpl();
    private Scanner sc = new Scanner(System.in);

    //修改测试
    @Test
    public void update() throws SQLException {
        //1.键盘录入，接收用户信息
        System.out.println("请输入学生id：");
       int id = sc.nextInt();
        //2.调用方法
        Student student = new Student();
        student.setId(id);

        while (true){
            System.out.println("***修改界面***");
            System.out.println("1.name");
            System.out.println("2.sex");
            System.out.println("3.age");
            System.out.println("4.password");
            System.out.println("5.退出");
            System.out.println("请输入想要修改的内容序号：");
            Scanner sc = new Scanner(System.in);
            String line = sc.next();
            String lines = "";
            int i= 0;
            switch (line) {
                case "1":
                    System.out.println("name:");
                    lines =TSUtils.readKeyBoard(15,false);
                    student.setName(lines);
                    break;
                case "2":
                    System.out.println("sex:");
                    lines =TSUtils.readKeySex(1);
                    student.setSex(lines);
                    break;
                case "3":
                    System.out.println("age:");
                    i = TSUtils.ageStock();
                    student.setAge(i);
                    break;
                case "4":
                    System.out.println("password:");
                    lines = TSUtils.readKeyBoard(6,false);
                    student.setPassword(lines);
                    break;
                case "5":
                    System.out.print("确认是否退出(Y/N)：");
                    if (TSUtils.readConfirmSelection() == 'Y' || TSUtils.readConfirmSelection() == 'y') {
                        System.out.println("您已成功退出，谢谢使用！");
                        System.exit(0);  //JVM退出
                    }
                    break;

            }
            boolean flag = studentService.updateMsgStu(student);
            //3.判断结果，输出不同语句
            if (flag) {
                //登录成功
                System.out.println("修改成功！");
            } else {
                System.out.println("修改失败！");
            }
        }

    }

}
